﻿using System;

namespace Aeon.Emulator.Instructions.FPU
{
    internal static class Fmul
    {
        [Opcode("D8/1 mf32", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultiplyST032(VirtualMachine vm, float value)
        {
            vm.Processor.FPU.ST0 *= value;
        }

        [Opcode("DC/1 mf64|D8C8+ st|DCC8 st0", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultiplyST064(VirtualMachine vm, double value)
        {
            vm.Processor.FPU.ST0 *= value;
        }

        [Opcode("DCC9", Name = "fmul st1", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST1(VirtualMachine vm)
        {
            double value = vm.Processor.FPU.GetRegisterValue(1);
            vm.Processor.FPU.SetRegisterValue(1, value * vm.Processor.FPU.ST0);
        }

        [Opcode("DCCA", Name = "fmul st2", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST2(VirtualMachine vm)
        {
            double value = vm.Processor.FPU.GetRegisterValue(2);
            vm.Processor.FPU.SetRegisterValue(2, value * vm.Processor.FPU.ST0);
        }

        [Opcode("DCCB", Name = "fmul st3", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST3(VirtualMachine vm)
        {
            double value = vm.Processor.FPU.GetRegisterValue(3);
            vm.Processor.FPU.SetRegisterValue(3, value * vm.Processor.FPU.ST0);
        }

        [Opcode("DCCC", Name = "fmul st4", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST4(VirtualMachine vm)
        {
            double value = vm.Processor.FPU.GetRegisterValue(4);
            vm.Processor.FPU.SetRegisterValue(4, value * vm.Processor.FPU.ST0);
        }

        [Opcode("DCCD", Name = "fmul st5", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST5(VirtualMachine vm)
        {
            double value = vm.Processor.FPU.GetRegisterValue(5);
            vm.Processor.FPU.SetRegisterValue(5, value * vm.Processor.FPU.ST0);
        }

        [Opcode("DCCE", Name = "fmul st6", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST6(VirtualMachine vm)
        {
            double value = vm.Processor.FPU.GetRegisterValue(6);
            vm.Processor.FPU.SetRegisterValue(6, value * vm.Processor.FPU.ST0);
        }

        [Opcode("DCCF", Name = "fmul st7", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST7(VirtualMachine vm)
        {
            double value = vm.Processor.FPU.GetRegisterValue(7);
            vm.Processor.FPU.SetRegisterValue(7, value * vm.Processor.FPU.ST0);
        }
    }

    internal static class Fmulp
    {
        [Opcode("DEC8", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultiplyToST0(VirtualMachine vm)
        {
            throw new InvalidOperationException();
        }

        [Opcode("DEC9", Name = "fmulp st1", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST1(VirtualMachine vm)
        {
            Fmul.MultplyToST1(vm);
            vm.Processor.FPU.Pop();
        }

        [Opcode("DECA", Name = "fmulp st2", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST2(VirtualMachine vm)
        {
            Fmul.MultplyToST2(vm);
            vm.Processor.FPU.Pop();
        }

        [Opcode("DECB", Name = "fmulp st3", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST3(VirtualMachine vm)
        {
            Fmul.MultplyToST3(vm);
            vm.Processor.FPU.Pop();
        }

        [Opcode("DECC", Name = "fmulp st4", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST4(VirtualMachine vm)
        {
            Fmul.MultplyToST4(vm);
            vm.Processor.FPU.Pop();
        }

        [Opcode("DECD", Name = "fmulp st5", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST5(VirtualMachine vm)
        {
            Fmul.MultplyToST5(vm);
            vm.Processor.FPU.Pop();
        }

        [Opcode("DECE", Name = "fmulp st6", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST6(VirtualMachine vm)
        {
            Fmul.MultplyToST6(vm);
            vm.Processor.FPU.Pop();
        }

        [Opcode("DECF", Name = "fmulp st7", OperandSize = 16 | 32, AddressSize = 16 | 32)]
        public static void MultplyToST7(VirtualMachine vm)
        {
            Fmul.MultplyToST7(vm);
            vm.Processor.FPU.Pop();
        }
    }
}
